import mongoose from "mongoose";
import logger from "./log";

function init(url) {
    mongoose.Promise = global.Promise;
    mongoose.connect(url);
    mongoose.connection.on('error', function (err) {
        throw new Error('Mongoose error: ' + err);
    });

    process.on('SIGINT', function () {
        mongoose.connection.close(function () {
            logger(module.filename).info('Mongoose default connection closed through app termination');
            process.exit(0);
        });
    });
}

export {
    init as initMongo
};